//
//  ZHFrendInfoView.swift
//  ZHWeibo
//
//  Created by user on 15/12/10.
//  Copyright © 2015年 heima. All rights reserved.
//

import UIKit

/// 如何声明一个内部的局部变量-声明会报错
//static margin:CGFloat = 10.0
class ZHFrendInfoView: UIView {
    
    //获取model,设置数据---计算属性,专门用来设置其他成员的值
    var statusUserViewModel:ZHStatusUserViewModel? {
        didSet{
            //头像
            /**
            - parameter placeholderImage: 这个参数有什么作用
            */
            headImageView.sd_setImageWithURL(NSURL(string: (statusUserViewModel?.userModel?.user?.profile_image_url)!), placeholderImage: UIImage(named: "avatar_default_big"))
            nameLabel.text = statusUserViewModel?.userModel?.user?.name
            timeLable.text = "呵呵"
            sourceLabel.text = "哈哈"
            VIPImageView.image = statusUserViewModel?.vipImage
            VerImageView.image = statusUserViewModel?.verIdentifierImage
            
            contentLabel.text = statusUserViewModel?.userModel?.text
        }
    }
    
    /**
      * 外部没有调用这个方法,那他是怎么调用的  
    */
    override init(frame: CGRect) {
        super.init(frame: frame)
        //设置UI
        setUpUI()
    }
    /**
     特点:
        * init开头
        * 没有关键字func
        * 没有返回值
     分类:
        * 不带参数的构造方法
        * 带参数的构造方法---构造函数的所有的参数名既是内部参数名又是外部参数名
        * 便利构造方法--convenience修饰
    */
//    override init(){
//        super.init()
//    }
    private func setUpUI(){
        addSubview(headImageView)
        addSubview(nameLabel)
        addSubview(timeLable)
        addSubview(VIPImageView)
        addSubview(VerImageView)
        addSubview(sourceLabel)
        addSubview(contentLabel)
        //添加约束
        headImageView.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(self).offset(margin)
            make.leading.equalTo(self).offset(margin)
            make.size.equalTo(CGSizeMake(35, 35))
        }
        nameLabel.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(headImageView)
            make.leading.equalTo(headImageView.snp_trailing).offset(margin)
        }
        VIPImageView.snp_makeConstraints { (make) -> Void in
            make.centerY.equalTo(nameLabel)
            make.leading.equalTo(nameLabel.snp_trailing).offset(margin)
        }
        timeLable.snp_makeConstraints { (make) -> Void in
            make.bottom.equalTo(headImageView)
            make.leading.equalTo(nameLabel)
        }
        sourceLabel.snp_makeConstraints { (make) -> Void in
            make.centerY.equalTo(timeLable)
            make.leading.equalTo(timeLable.snp_trailing).offset(margin)
        }
        VerImageView.snp_makeConstraints { (make) -> Void in
            make.centerX.equalTo(headImageView.snp_trailing)
            make.centerY.equalTo(headImageView.snp_bottom)
        }
        contentLabel.snp_makeConstraints { (make) -> Void in
            make.leading.equalTo(headImageView)
            make.top.equalTo(headImageView.snp_bottom).offset(margin)
        }
        
        //关键点,约束整个view的高度
        snp_makeConstraints { (make) -> Void in
            make.bottom.equalTo(contentLabel).offset(margin)
        }
    }
    
    //懒加载控件---头像
    private lazy var headImageView: UIImageView = UIImageView(image: UIImage(named: "avatar_default_big"))
    //懒加载控件---昵称
    private lazy var nameLabel: UILabel = UILabel(textColor: UIColor.darkGrayColor(), textFont: 14)
    //懒加载控件---发布时间
    private lazy var timeLable: UILabel = UILabel(textColor: UIColor.orangeColor(), textFont: 10)
    //懒加载控件---VIP
    private lazy var VIPImageView: UIImageView = UIImageView(image: UIImage(named: "common_icon_membership"))
    //认证
    private lazy var VerImageView: UIImageView = UIImageView(image: UIImage(named: "avatar_vip"))
    //来源
    private lazy var sourceLabel: UILabel = UILabel(textColor: UIColor.lightGrayColor(), textFont: 10)
    //微博内容
    private lazy var contentLabel = UILabel(textColor: UIColor.darkGrayColor(), textFont: 15, maxWidth: ScreenWith - margin * 2)
    //控件设置约束
    
    
    

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}
